package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.UserDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    /**
     * 根据用户名获取用户信息(用户名，密码，权限)
     * @param username
     * @return
     */
    @Override
    public SysUser findByUsername(String username) {
        return userDao.findByUsername(username);
    }


    public PageResult pageQuery(QueryPageBean queryPageBean) {
        //1. 开始分页(把页面和每页条数封装成Page，并存储到ThreadLocal中)
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //2. 条件查询(请求会被拦截器拦截，根据page参数和映射文件中的sql语句拼接 分页查询的sql语句)
        Page<SysUser> page = userDao.findByCondition(queryPageBean.getQueryString());
        //3. 返回结构
        return new PageResult(page.getTotal(), page);
    }

    @Override
    public void add(SysUser sysUser, Integer[] roleIds) {

    }
}
